home *** CD-ROM | disk | FTP | other *** search
/ .net (Turkey) 1998 March / .net Internet Dergisi - CD 5.iso / mac / CON_BM / 00291_Script_ScrollBox < prev    next >
Text File  |  1997-11-07  |  3KB  |  113 lines

  1. -- Parent script for Scroll Bars
  2.  
  3.  
  4. property barSprite, boxSprite, clickHeight, topLimit, bottomLimit, scrollLength, curLine, controlField,fieldPixToBarPix,controlFieldLength
  5.  
  6. on new me,bar,box,hght
  7.   set curLine = 1
  8.   set barSprite = bar
  9.   set boxSprite = box
  10.   set clickHeight = hght
  11.   return me  
  12. end
  13.  
  14. on init me,theFld
  15.   -- store some variables based on the size of the field
  16.   --
  17.   set topLimit = (the top of sprite barSprite + clickHeight) + ((the height of sprite boxSprite)/2)
  18.   set bottomLimit = the bottom of sprite barSprite - clickHeight - ((the height of sprite boxSprite)/2)
  19.   set scrollLength = bottomLimit - topLimit
  20.   calibrate me,theFld
  21.   puppetSprite boxSprite,TRUE
  22.   --  set the loch of Sprite boxSprite = 300
  23.   --  set the locv of Sprite boxSprite = 300
  24.   --  updatestage
  25. end
  26.  
  27. on calibrate me,theFld
  28.   -- calculate the ratio of the size of the field to the size of the scrollbar
  29.   --
  30.   set controlField = the number of member theFld
  31.   set controlFieldLength = getAt(charPosToLoc(member controlField, the number of chars in field controlField),2)
  32.   set fieldPixToBarPix = controlFieldLength/scrollLength
  33. end
  34.  
  35.  
  36. on clickBox me
  37.   -- move the scroll box and scroll the field with it
  38.   --
  39.   repeat while the stillDown
  40.     if the mouseV >= topLimit and the mouseV <= bottomLimit then
  41.       set the locV of sprite boxSprite = the mouseV
  42.       updatestage
  43.     end if    
  44.   end repeat
  45.   set newloc = the locV of sprite boxSprite
  46.   if newLoc < topLimit + 10 then
  47.     boxToTop me
  48.   else
  49.     set the scrollTop of member controlField = integer((newLoc - topLimit) * fieldPixToBarPix)
  50.   end if
  51. end
  52.  
  53. on clickEnd me
  54.   -- if user clicked at very top or bottom of scrollbar, scroll the field
  55.   --
  56.   set saveV = getAt(the clickLoc,2)
  57.   if saveV < the top of sprite barSprite + clickHeight then
  58.     set the membernum of sprite 28 to member "txt_butup"
  59.     updateStage
  60.     scrollUp me
  61.   else if saveV > the bottom of sprite barSprite - clickHeight then
  62.    set the membernum of sprite 28 to member "txt_butdown"
  63.    updateStage 
  64.     scrollDown me
  65.   end if
  66. end
  67.  
  68. on scrollDown me
  69.   -- scroll the field down, move box too
  70.   --
  71.   if fieldPixToBarPix < 1 then exit
  72.   repeat while the stillDown
  73.     if the locV of sprite boxSprite < bottomLimit then
  74.       scrollByLine member controlField, 1
  75.       moveBox me
  76.     end if
  77.   end repeat  
  78. end 
  79.  
  80. on scrollUp me
  81.   -- scroll the field up, move box too
  82.   --
  83.   if fieldPixToBarPix < 1 then exit
  84.   repeat while the stillDown
  85.     scrollByLine member controlField, -1
  86.     moveBox me
  87.   end repeat  
  88. end
  89.  
  90. on moveBox me
  91.   -- move box in relation to scroll position of field
  92.   --
  93.   if fieldPixToBarPix < 1 then exit
  94.   set newPos = (the scrollTop of member "NameofFieldToControl")/fieldPixToBarPix
  95.   set newPos = topLimit + newPos
  96.   if newPos <= bottomLimit then
  97.     set the locV of sprite boxSprite = newPos
  98.     updateStage  
  99.   end if  
  100. end
  101.  
  102. on boxToTop me
  103.   -- scroll field to top and move box to top of scrollbar
  104.   --
  105.   set the locV of sprite boxSprite = topLimit
  106.   updateStage  
  107.   --  set the scrollTop of member controlField = 1
  108.   set the scrollTop of member "NameofFieldToControl" = 1
  109.   updatestage
  110.   moveBox me
  111.   updatestage
  112. end
  113.